package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Dept;
import cn.kgc.vue.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/7/3
 * @description
 */
@RestController
@RequestMapping("dept")
@Api(tags = "部门模块")
public class DeptController {

    @Resource
    private DeptService deptService;
    @ApiOperation("部门列表")
    @GetMapping("list")
    public ResponseResult deptList(){
        List<Dept> list = deptService.list();
        return ResponseResult.success().data("deptList",list);
    }

    @ApiOperation("部门分页")
    @PostMapping("page")
    public ResponseResult deptPage(@RequestBody QueryCondition<Dept> queryCondition){

        return deptService.deptPage(queryCondition);
    }

    @ApiOperation("部门新增/修改")
    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateDept(@RequestBody Dept dept){

        deptService.saveOrUpdate(dept);
        return ResponseResult.success();
    }


    @ApiOperation("删除部门")
    @DeleteMapping("delete/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){

        return deptService.delete(id);
    }
}
